package cn.edu.wynu.api.collect.list;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ListToArrayLearn {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");

        // 直接调用toArray()方法会丢失类型信息
        Object[] array = list.toArray();
        for (Object o : array) {
            System.out.println(o);
        }

        // 调用toArray(T[])方法会保留类型信息
        String[] array1 = list.toArray(new String[0]);
        for (String s : array1) {
            System.out.println(s);
        }

        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            System.out.println(random.nextInt(50));
        }
    }
}
